//alu.h

 /*
 * Team Name: Focus
 * Team Members: Diana Groun, Edward Bassan
 * File Name; alu.h
 * Description: This file contains the definition of an alu and definition for all its members
 */

#include "Register.h"
#include "RegisterFile.h"


#ifndef ALU_H_
#define ALU_H_

//---- Modifier --------//
#define ADD  0
#define SUB  1
#define MUL  2
#define DIV  3
#define AND  4
#define OR   5
#define XOR  6
#define NOT  7
#define SHL  8
#define SHR  9
//--------------------//


typedef struct alu{
            //Alu fields.
        RegisterPtr operandA;
        RegisterPtr operandB;
        RegisterPtr resultR;
        int modifier, negFlag, zeroFlag, posFlag, carryFlag, overflowFlag;

        //Member Functions.
        int (*signOf) (struct alu*, unsigned short);
        int(*negation)(struct alu*);
        int(*addition)(struct alu*);
        int(*subtraction)(struct alu*);
        int(*multiplication)(struct alu*);
        int(*division)(struct alu*, RegisterPtr);
        int(*xor)(struct alu*);
        int(*and)(struct alu*);
        int(*or)(struct alu*);
        int(*not)(struct alu*);
        int(*isUnary)(int);
        unsigned short(*getResult)(struct alu*);
        int(*setFlags)(struct alu*);
        int(*aluOperation)(struct alu*, int);
        int(*displayAlu)(struct alu*);
        int(*shiftLeft)(struct alu*);
        int(*shiftRight)(struct alu*);


}AluStr;

typedef AluStr * AluPtr;
AluPtr aluConstructor();
//Functions
int signOf(AluPtr this, unsigned short operand);/* sign of operand */
int displayAlu(AluPtr this);/* resultR <- -operandA */
int negation(AluPtr this);  /* resultR <- -operandA */
int addition(AluPtr this); /* resultR <- operandA + operandB */
int subtraction(AluPtr this); /* resultR <- operandA - operandB */
int and(AluPtr this); /* resultR <- operandA & operandB */
int or(AluPtr this); /* resultR <- operandA | operandB */
int not(AluPtr this);    /* resultR <- ~operandA */
unsigned short getResult(AluPtr this); /* resultR <- getResult*/
int isUnary(int opcode);
int aluOperation(AluPtr this, int modifier);/* operation <- modifier */
int multiplication(AluPtr this);/* resultR <--operandA * operandB */
int division(AluPtr this, RegisterPtr remainder);/* resultR <- -operandA / operandB */
int xor(AluPtr this);/* resultR <- -operandA ^ operandB*/
int shiftLeft(AluPtr this);/* resultR <- -operandA << 2 */
int shiftRight(AluPtr this);/* resultR <- -operandA >> 2 */
int setFlags(AluPtr this);/* NZCO <--   negativeFlag, zeroFlag, carryFlag and overFlowFlag*/

#endif /* ALU_H_ */


